package com.zhengdongzulin.zuke.app.login

import androidx.lifecycle.rxLifeScope
import com.lxj.androidktx.livedata.StateLiveData
import com.zhengdongzulin.zuke.app.Api
import com.zhengdongzulin.zuke.base.BaseViewModel
import rxhttp.wrapper.param.RxHttp
import rxhttp.wrapper.param.toResponse

class ForgetVm : BaseViewModel() {

    var forgot_password: StateLiveData<String> = StateLiveData()

    fun forgot_password(phone: String, code: String, pwd: String,api:String) {
        rxLifeScope.launch(
                {
                    var r = RxHttp.postJson(api)
                            .add("phone", phone)
                            .add("code", code)
                            .add("password", pwd)
                            .add("confirmPassword", pwd)
                            .toResponse<String>()
                            .await()
                    forgot_password.postValueAndSuccess(r)
                }, {
            assignment(it, forgot_password)
        }
        )
    }

    var send_code: StateLiveData<String> = StateLiveData()

    fun send_code(phone: String,type :String) {
        rxLifeScope.launch(
                {
                    var r = RxHttp.postJson(Api.SEND_CODE)
                            .add("type", type)
                            .add("phone", phone)
                            .toResponse<String>()
                            .await()
                    send_code.postValueAndSuccess(r)
                }, {
            assignment(it, send_code)
        }
        )
    }

}